import java.util.Deque;
import java.util.LinkedList;

/**
 * Created by forcht on 2018/5/2.
 */
public class Solution {
    public int evalRPN(String[] tokens) {
        Deque<Integer> stack = new LinkedList<>();
        for (int i = 0; i < tokens.length; i++) {
            try{
                Integer integer = Integer.valueOf(tokens[i]);
                stack.push(integer);
            }catch (Exception e){
                int n=stack.pop();
                int m=stack.pop();
                switch (tokens[i]){
                    case "+":
                        stack.push(m+n);
                        break;
                    case "-":
                        stack.push(m-n);
                        break;
                    case "*":
                        stack.push(m*n);
                        break;
                    case "/":
                        stack.push(m/n);
                }
            }
        }
        return stack.pop();
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        String[] s = {"9", "-3", "/"};
        System.out.println(solution.evalRPN(s));
    }
}
